<template>
    <div class="doctorreviewlist">
        <Row>
            <Col :xs="24">
            <!-- <div class="margin-up-down">
                <fourLevelLinkage
                    @changeProvince="changeProvince"
                    @changeCity="changeCity"
                    @changeArea="changeArea"
                    @changeHospital="changeHospital"
                    :province="province"
                    :city="city"
                    :area="area"
                    :hospital="hospital"
                    :isBack="isBack"
                ></fourLevelLinkage>
            </div> -->
            <div class="margin-up-down">
               <Input class="w-input" v-model="searchKey" :placeholder="'请输入机构名称/医生姓名/手机号'" clearable/> 
            </div>  
            <div class="margin-up-down">
                <Select class="w-select" clearable v-model="type" placeholder="角色类型" style='width:130px;'>
                    <Option :value="1" :key="1" style='text-align:center'>医生</Option>
                    <Option :value="2" :key="2" style='text-align:center'>药师</Option>
                </Select>
            </div>  
            <div class="margin-up-down">
                <Select class="w-select" clearable v-model="dictType" placeholder="职称级别" style='width:130px;'>
                    <Option
                        v-for="item in titleList"
                        :value="item.dictType"
                        :key="item.dictType"
                        style='text-align:center'
                    >{{item.dictName}}</Option>
                </Select>
            </div>  
            <!-- <div class="margin-up-down">
                <Select class="w-select" clearable v-model="authStatus" placeholder="认证状态">
                    <Option v-for="(item,index) in statusList" :value="index" :key="index" style='text-align:center'>{{item}}</Option>
                </Select>
            </div>   -->
            <div class="margin-up-down">
                <Button type="primary" @click="loadPage(1)">
                    <Icon type="ios-search" size="14"/>
                </Button>
            </div>  
            </Col>
        </Row>
        <Table class="m-table" :loading="tableLoading" stripe :columns="columns" :data="doctorList"></Table>
        <div class="page">
            <Page :total="count" :current='pageNo' :page-size="pageSize" show-total show-elevator @on-change="loadPage"/>
        </div>
        <Modal
            title="提示："
            @on-ok="ok"
            @on-cancel="cancel"
            v-model="modalConfirm"
            class-name="vertical-center-modal"
        >
            <p>{{confirmInfo}}</p>
        </Modal>
    </div>
</template>
<script>
import api from "@/api/commonApi";
import fourLevelLinkage from "@/components/fourLevelLinkage";
export default {
    data() {
        return {
            tableLoading: false,
            province: null,
            city: null,
            area: null,
            hospital: null,
            searchKey: "",
            type: '', // 1 医生 2药师
            titleList: "",
            dictType: "",
            statusList: ["未认证", "审核中", "审核通过", "审核未通过"],
            openList: ["未开通", "未开通", "已开通", "未开通"],
            authStatus: null,
            columns: [
                { title: "排序", width: 60, key: "iNum", align: "center",
                    render: (h, params) => {
                        let iNum = (this.pageNo-1)*this.pageSize + params.index +1;
                        return h("span", iNum);
                    }
                },
                {
                    title: "机构",
                    key: "hospitalname",
                    align: "center"
                },
                {
                    title: "科室",
                    key: "deptName",
                    align: "center"
                },
                {
                    title: "人员类型",
                    key: "type",
                    align: "center",
                    render(h, params) {
                        return ['','医师', '药师', '护士','检验师'][params.row.type];
                    }
                },
                { title: "职称", key: "titleName", align: "center"},
                { title: "姓名", key: "name", align: "center" },
                {title: "电话",key: "phone",align: "center"},
                // {
                //     title: "认证状态",
                //     key: "authStatus",
                //     align: "center",
                //     // width: 90
                // },
                {
                    title: "设置",
                    key: "operate",
                    align: "center",
                    width: 190,
                    // fixed:"right",
                    render: (h, params) => {
                        let id = params.row.id; 
                        let type = params.row.type;
                        return [
                            h(
                                "span",
                                {
                                    attrs: {
                                        href: "javascript:void(0);"
                                    },
                                    style: {
                                        color: '#5362e1',
                                        margin: "0px 6px"
                                    },
                                    on: {
                                        click: () => {
                                            //   公用方法
                                            this.functionJS.queryNavgationTo(
                                                this,
                                                "/index/doctorOperation/doctorReview/review",
                                                {
                                                    id,
                                                    pageNo: this.pageNo,
                                                    province: this.province,
                                                    city: this.city,
                                                    area: this.area,
                                                    hospital: this.hospital,
                                                    searchKey: this.searchKey,
                                                    dictType: this.dictType,
                                                    authStatus: this.authStatus,
                                                    hospitalId: this.hospitalId,
                                                    isBack: 2,
                                                    type,
                                                    jgtype: 'jianguan'
                                                }
                                            );
                                        }
                                    }
                                },
                                '查看'
                            ),
                        ];
                    }
                }
            ],
            doctorList: [],
            count: 0,
            pageSize: 10,
            pageNo: 1,
            modalConfirm: false,
            confirmInfo: "",
            delIndex: null,
            delId: null,
            identity: null,
            identityCoding: null,
            ownArea: null,
            isBack: 1,
            hospitalId: '',
        };
    },
    components: {
        fourLevelLinkage
    },
    created() {
        this.province = this.$route.query.province
            ? parseInt(this.$route.query.province)
            : null;
        this.city = this.$route.query.city
            ? parseInt(this.$route.query.city)
            : null;
        this.area = this.$route.query.area
            ? parseInt(this.$route.query.area)
            : null;
        this.hospital = this.$route.query.hospital
            ? this.$route.query.hospital
            : null;
        this.hospitalId = this.$route.query.hospitalId
            ? this.$route.query.hospitalId
            : null;
        this.isBack = this.$route.query.isBack
            ? parseInt(this.$route.query.isBack)
            : 1;
        this.searchKey = this.$route.query.searchKey
            ? this.$route.query.searchKey
            : "";
        this.dictType = this.$route.query.dictType
            ? this.$route.query.dictType
            : "";
        this.authStatus =
            this.$route.query.authStatus == null
                ? null
                : parseInt(this.$route.query.authStatus);
        let breadList = [
            { path: "/index", title: "首页" },
            {
                path: "/index/operation/doctorManagement/index",
                title: "医生端运营"
            },
            {
                path: "/index/operation/doctorreview/list",
                title: "认证管理"
            }
        ];
        this.$emit("changeBreadList", breadList);
    },
    mounted() {
        //获取职称列表
        this.$axios
            .post(api.getTitle,{})
            .then(resp => {
                this.titleList = resp.data.object;
            })
            .catch(err => {
                console.log(err);
            });
        let pageNo = this.$route.query.pageNo
            ? parseInt(this.$route.query.pageNo)
            : 1;
        //上来就加载第一页数据
        this.loadPage(pageNo);
    },
    methods: {
        changeProvince(val) {
            this.province = val;
        },
        changeCity(val) {
            this.city = val;
        },
        changeArea(val) {
            this.area = val;
        },
        changeHospital(val) {
            this.hospital = val;
        },
        //加载列表数据
        loadPage(pageNo) {
            this.pageNo = pageNo;
            var params = {};
            params.provinceCode = this.province ? this.province : null;
            params.cityCode = this.city ? this.city : null;
            params.areaCode = this.area ? this.area : null;
            params.hospitalId = this.hospitalId;
            params.title = this.dictType ? this.dictType : null;
            params.authStatus = this.authStatus;
            params.searchKey = this.searchKey ? this.searchKey : null;
            params.pageNo = pageNo;
            params.pageSize = this.pageSize;
            if (this.type) {
                params.type = this.type ? this.type : null;
            }
            this.tableLoading = true;
            this.$axios
                .post(api.findOperateSuperviseDoctorPageList, params)
                .then(resp => {
                    if (resp.data.success) {
                        this.count = resp.data.object.total;
                        this.doctorList = resp.data.object.records;
                        if(this.doctorList){
                            for (let i = 0; i < this.doctorList.length; i++) {
                                let item = this.doctorList[i];
                                this.doctorList[i].iNum = i + 1;
                                this.tryCatch(item.docIcon) &&
                                    (this.doctorList[i].avatar =
                                        this.fileBaseUrl +
                                        this.tryCatch(item.docIcon).fileName);
                                this.doctorList[i].imginquiry = this.openList[
                                    this.doctorList[i].authStatus
                                ];
                                this.doctorList[i].phoneinquiry = this.openList[
                                    this.doctorList[i].authStatus
                                ];
                                this.doctorList[i].videoinquiry = this.openList[
                                    this.doctorList[i].authStatus
                                ];
                                // this.doctorList[i].homedoctor = this.openList[
                                //     this.doctorList[i].authStatus
                                // ];
                                this.doctorList[i].authStatus = this.statusList[
                                    this.doctorList[i].authStatus
                                ];
                                this.doctorList[i].operate = this.doctorList[i].id;
                            }
                        } else {
                            this.doctorList = []
                        }                       
                    } else {
                        this.$Message.info("不允许访问");
                    }
                    this.tableLoading = false;
                })
                .catch(err => {
                    this.tableLoading = false;
                    console.log(err);
                });
        },
        //更新缓存
        update(id){
            let params = {};
            params.id = id;
            this.$axios
                .post(api.updateDoctorCache, params)
                .then(resp => {
                    if (resp.data.success) {
                        this.$Message.info("更新成功");
                    } else {
                    }
                })
                .catch(err => {
                    // this.$Message.info("服务器超时，请重试");
                });
        },
        delDoctor(index, id, name) {
            this.confirmInfo = "是否确认删除“" + name + "”?";
            this.modalConfirm = true;
            this.delIndex = index;
            this.delId = id;
        },
        ok() {
            let params = {};
            params.id = this.delId;
            this.$axios
                .post(api.delReviewDoctor, params)
                .then(resp => {
                    if (resp.data.success) {
                        this.doctorList.splice(this.delIndex, 1);
                        this.modalConfirm = false;
                        this.confirmInfo = "";
                        this.delIndex = null;
                        this.delId = null;
                        this.$Message.info("删除成功");
                    } else {
                        this.$Message.info("删除失败，请重试");
                    }
                })
                .catch(err => {
                    // this.$Message.info("服务器超时，请重试");
                });
        },
        cancel() {
            this.modalConfirm = false;
            this.confirmInfo = "";
            this.delIndex = null;
            this.delId = null;
        }
    }
};
</script>
<style lang="less" scoped>
.doctorreviewlist {
    padding: 10px;
    width: 100%;
    background: #ffffff;
    box-sizing: border-box;
    .margin-up-down {
        display: inline-block;
        margin: 10px 0;
    }
    .page{
      text-align: center;
    }
    .w-select {
        width: 100px;
    }
    .w-select-hos {
        width: 180px;
    }
    .w-input {
        width: 200px;
    }
    .m-table {
        margin: 10px 0;
    }
}
</style>